package com.idheima.Stream.streamFangfa;

import java.util.ArrayList;
import java.util.List;

//掌握Stream流中的常用方法
public class Test {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        list.add(new Student("小王", 28, 90.0));
        list.add(new Student("小张", 26, 85.0));
        list.add(new Student("小李", 17, 80.5));
        list.add(new Student("小赵", 16, 99.0));
        list.add(new Student("小王", 20, 60.0));
        list.stream().filter(s -> s.getScore() >= 60).sorted((s1, s2) -> Double.compare(s2.getScore(), s1.getScore()))
                .forEach(s -> System.out.println(s.getName()));
        System.out.println("--------------------------------------------------------------------------------");
        //找出年纪大于18，小于等于25的学生
        list.stream()
                .filter(s -> s.getAge() > 18 && s.getAge() <= 25)
                .forEach(s -> System.out.println(s.getName()));
        System.out.println("---------------------");
        //获取考试成绩的前三名
        list.stream().sorted((s1,s2)->Double.compare(s2.getScore(),s1.getScore()))
                .limit(3)
                .forEach(s -> System.out.println(s.getName()));
        System.out.println("---------------------");
        //获取考试成绩后三名的学生
        list.stream().sorted((s1,s2)->Double.compare(s1.getScore(),s2.getScore()))
                .skip(list.size()-3)
                .forEach(System.out::println);
        System.out.println("---------------------");
        //找出年纪大于18的并删除重复的姓名
        list.stream()
                .filter(s -> s.getAge() > 18)
                .distinct()
                .forEach(System.out ::println);

        System.out.println("---------------------");

    }
}
